﻿Imports System.ServiceModel
Imports System.Collections.Generic


Namespace DotNetNuke.Modules.IWebCF

    <IWebContract(CoreBindings.ws2007HttpBinding, Address:="IWebTabManager", Name:="IWebTabManager")> _
    <ServiceContract(Namespace:="http://webservices.DotNetNuke.com/2007/12/IWebTabManager")> _
    Public Interface IWebTabManager


        <OperationContract(Action:="GetTabNamesOnPortal")> _
     Function GetTabNamesOnPortal(ByVal msg As IWebRequest) As IWebResponse(Of List(Of String))


    End Interface


    Partial Public Class CoreService
        Implements IWebTabManager

        <IWebMethod( _
             Company:="DotNetNuke", _
             Application:="IWeb", _
             Name:="GetTabNamesOnPortal", _
             Description:="Retrieves Tab Names on Portal", _
             Group1:="General", Group2:="Portal", _
             DefaultSecuritySetting:=IWebMethodAttribute.MethodSecurityLevels.Host)> _
        Public Function GetTabNamesOnPortal(ByVal msg As IWebRequest) As IWebResponse(Of System.Collections.Generic.List(Of String)) Implements IWebTabManager.GetTabNamesOnPortal

            Dim authendication As New IWebAuthentication(msg.Header)

            If authendication.ValidAndAuthorized() Then

                Dim tabCtrl As New TabController



                Dim results As New List(Of String)

                Dim tabs As ArrayList = tabCtrl.GetTabs(msg.Header.PortalID)

                For Each t As Entities.Tabs.TabInfo In tabs

                    If Not t.IsAdminTab AndAlso Not t.IsSuperTab Then

                        'Check user permissions

                        results.Add(t.TabName)

                    End If
                Next


                Return New IWebResponse(Of List(Of String))(results)


            Else
                Throw Me.GetLoggedNotAuthorizedEx(msg.Header)

            End If

        End Function
    End Class
End Namespace


Namespace DotNetNuke.Modules.IWebCF

    <IWebContract(CoreBindings.ws2007HttpBinding, Address:="IWebModuleManager", Name:="IWebModuleManager")> _
    <ServiceContract(Namespace:="http://webservices.DotNetNuke.com/2007/12/IWebModuleManager")> _
    Public Interface IWebModuleManager


        <OperationContract(Action:="GetModuleNames")> _
       Function GetModuleNames(ByVal msg As IWebRequest) As IWebResponse(Of String)


    End Interface


    Partial Public Class CoreService
        Implements IWebModuleManager

        <IWebMethod( _
             Company:="ITLackey", _
             Application:="ExampleApp", _
             Name:="GetModuleNames", _
             Description:="Get modules on the portal", _
             Group1:="General", Group2:="Portal", _
             DefaultSecuritySetting:=IWebMethodAttribute.MethodSecurityLevels.Host)> _
        Public Function GetModuleNames(ByVal msg As IWebRequest) As IWebResponse(Of String) Implements IWebModuleManager.GetModuleNames

            Dim authentication As New IWebAuthentication(msg.Header)

            If authentication.ValidAndAuthorized() Then


                Dim result As String

                result = String.Empty


                Dim modCtrl As New Entities.Modules.ModuleController

                Dim mods As ArrayList = modCtrl.GetModules(msg.Header.PortalID)

                If mods IsNot Nothing AndAlso mods.Count > 0 Then

                    result = DirectCast(mods.Item(0), Entities.Modules.ModuleInfo).ModuleTitle

                End If

                Return New IWebResponse(Of String)(result)


            Else
                Throw Me.GetLoggedNotAuthorizedEx(msg.Header)

            End If

        End Function

    End Class

End Namespace
